import { http } from "@/utils/http";
import { createFormData } from "@pureadmin/utils";

export type AddAttachment = {
	file: File;
	saveTo: string;
	description: string;
};
export type UpdateAttachment = {
	id: string;
	file: File;
	saveTo: string;
	description: string;
};


export type AttachmentResult = {
	success: boolean;
	data: {
		id: string;
	};
	code: number;
	msg: string;
};

export const  genAttachmentUrl = (attachmentId: string):string => {
	return http.genAttachmentUrl(attachmentId);
};


export const uploadAttachment = (data: AddAttachment) => {
	return http.request<AttachmentResult>("post", "/attachment/upload", { 
		headers:{
		 "Content-Type": "multipart/form-data",
		},
		data:createFormData(data) 
	});
};

export const updateAttachment = (data: UpdateAttachment) => {
	return http.request<AttachmentResult>("post", "/attachment/update", { 
		headers:{
		 "Content-Type": "multipart/form-data",
		},
		data:createFormData(data) 
	});
};
export const deleteAttachment = (attachmentId: string) => {
	return http.request<any>("delete", "/attachment/deleteAttachment", { attachmentId });
};